﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.BLL;
using Grove.ORM;
using HZ.MBSM.Model;
using HZ.MBSM.DBUtility;
using System.Drawing;
public partial class Bidder_LookWholeProduct : System.Web.UI.Page
{
    public string _Projecitd = "0";
    protected void Page_Load(object sender, EventArgs e)
    {

        if (HZ.MBSM.BLL.Login.CheckAssert(this.UseAccountType))
        {
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];

            if (_Account != null)
            {
                _Projecitd = SysFun.IsSQL(SysFun.ToTrim(Request.QueryString["ProjectId"]));
                if (!IsPostBack)
                {

                }


               
                if (_Projecitd != "1" && _Projecitd != "2")
                {
                    Response.Write("<script language=JavaScript>alert('该项目不存在！');window.close();</script>");
                }
                else
                {
                    if (_Projecitd.Equals("1")) Ltitle.Text = "维护基本药投标品种";
                    else Ltitle.Text = "维护非基本药投标品种";
                    showGridView();
                    if (!HZ.MBSM.BLL.Company.isbidpass(_Account.AccountId.ToString(), _Projecitd)) //是否能投标
                    {
                        GridView1.Columns[9].Visible = false;
                        TBlink.Visible = false;
                    }
                    else
                    {
                        TBlink.InnerHtml = "<a href=\"../Company/Goodsbid_add.aspx?id=" + _Projecitd + "\" target=\"_blank\" style=\"font-stretch: wider\">添加投标品种</a>";
                    }
                }

            }

        }
    }

    public void showGridView()
    {

        string strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        if (_Projecitd == "1") //基本
        {
            dbPage.Table = "BidGoods_View";                                               //要查询的表明
            dbPage.Key = "bidid";                                               //表的主键    
            dbPage.Where = strConditions;                                           //查询条件    
            dbPage.SelectField = "bidid,goodsid as GoodsByCompanyId,productname_gjsp as pn,Outlookc_gjsp as ou ,Medicinemodel_gjsp as me,unit_gjsp as un,factor as fa,goodsother_bc as bc,NoPass,case CheckStatus when '1' then '审核通过' when '2' then '审核未通过'  else '未审核' end as CheckStatus";//要显示的字段
            dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
            dbPage.PageSize = 10;                                                    //没有显示记录条数   
            dbPage.OrderBy = "productname,medicinemodel,outlookc,bidid";                  //排序字段
            System.Data.IDataReader dr = dbPage.ExecuteReader();
            GridView1.Columns[6].Visible = false;
            GridView1.DataSource = dr;
            GridView1.DataBind();
            dr.Close();
            //dr.Dispose();
            dbPage.Db.Close();
            db.Close();
            //08.18
            dr = null;
            db = null;
        }
        else   //非基本
        {
            dbPage.Table = "GoodsByCompany,Project_Bid";                                               //要查询的表明
            dbPage.Key = "bidid";                                               //表的主键    
            dbPage.Where = strConditions;                                           //查询条件    
            dbPage.SelectField = "bidid,GoodsByCompanyId,productname as pn,Medicinemodel as me,Outlookc as ou,unit as un,Factor as fa,'' as bc,NoPass,case Project_Bid.CheckStatus when '1' then '审核通过' when '2' then '审核未通过'  else '未审核' end as CheckStatus, CASE QualityLevels " + ConfigurationManager.AppSettings["QualityLevels"].ToString() + " END AS QualityLevels ";//要显示的字段
            dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
            dbPage.PageSize = 10;                                                    //没有显示记录条数   
            dbPage.OrderBy = "productname,medicinemodel,outlookc,bidid";                  //排序字段
            System.Data.IDataReader dr = dbPage.ExecuteReader();
            GridView1.DataSource = dr;
            GridView1.DataBind();
            dr.Close();
            //dr.Dispose();
            dbPage.Db.Close();
            db.Close();
            //08.18
            dr = null;
            db = null;
        }

        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键

    }

    public string fctConditions()
    {
        Int64 Account_tjr;
        string _strWhere = "";
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_Projecitd == "1") //非基本
        {
             _strWhere = "and   projectid=" + _Projecitd + " ";
        }
        else
        {
           _strWhere = "and GoodsByCompanyId=goodsid and projectid=" + _Projecitd + " ";
        }
        if (_Account != null)
        {
            Account_tjr = _Account.AccountId;

            _strWhere += @"and  Accountid_tjr=" + Account_tjr + " ";

            //药品通用名或拼音码

            string _strProductName = SysFun.ToTrim(txtProductName.Text);
            if (_strProductName != "")
            {
                _strWhere += "and  (ProductName like '%" + _strProductName + "%' ) ";
            }

            //txtMedicinemodel
            //剂型
            string _strMedicinemodel = SysFun.ToTrim(txtMedicinemodel.Text);
            if (_strMedicinemodel != "")
            {
                _strWhere += "and  Medicinemodel like '%" + _strMedicinemodel + "%' ";
            }

            //规格
            string _strOutlookc = SysFun.ToTrim(txtOutlookc.Text);
            if (_strOutlookc != "")
            {
                _strWhere += " and Outlookc like '%" + _strOutlookc + "%'";
            }


            //流水号

            string _strGoodsId = SysFun.ToTrim(txtGoodsId.Text);
            if (_strGoodsId != "")
            {
                if (_Projecitd == "1") //非基本
                {
                    _strWhere += " And goodsid =" + _strGoodsId + " ";
                }
                else
                {
                    _strWhere += " And GoodsByCompanyId =" + _strGoodsId + " ";
                }
            }

        }
        if (_strWhere != "")
        {
            _strWhere = "  " + _strWhere.Remove(0, 3);
        }

        return _strWhere;
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        if (e.CommandName == "未审核")
        {
            HZ.MBSM.BLL.Goods bllgoods = new HZ.MBSM.BLL.Goods();
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            if (bllgoods.DeletBid(Convert.ToInt32(e.CommandArgument), _Account.AccountId.ToString()) > 0)
            {
                HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "删除", "Project_Bid", "bllgoods.GoodsByCompanyDelete(GoodsByCompanyId)" + e.CommandArgument, "../Company/GoodsList.aspx");

                showGridView();
                Response.Write("<script>alert('删除成功！！！');</script>");

            }
            else
            {
                Response.Write("<script>alert('发生异常！！！');</script>");
            }
        }
        else if (e.CommandName == "审核通过")
        {
            Response.Write("<script>alert('审核通过品种不让删除！！！');</script>");
        }

        else if (e.CommandName == "审核未通过")
        {
            Response.Write("<script>alert('审核未通过品种不让删除！！！');</script>");
        }
    }
    #region IPageDescribe 成员

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCompany);
            return _AccountType;
        }
    }

    #endregion
}
